package com.iot.ammeter.controller.equipment;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iot.ammeter.anno.LogAnnotation;
import com.iot.ammeter.dto.web.equipment.EquipmentModelDTO;
import com.iot.ammeter.responseResult.ResponseResult;
import com.iot.ammeter.service.web.equipment.EquipmentModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备型号 前端控制器
 * </p>
 *
 * @author basil
 * @since 2021-09-25
 */
@RestController
@Api(tags = {"设备型号管理"})
@RequestMapping("/api/equipment_model")
public class EquipmentModelController {

    private final EquipmentModelService equipmentModelService;

    public EquipmentModelController(EquipmentModelService equipmentModelService) {
        this.equipmentModelService = equipmentModelService;
    }

    /**
     * 添加设备型号
     *
     * @param equipmentModelDTO 设备型号信息
     * @return 添加成功或者失败json数据
     */
    @ApiOperation("添加设备型号")
    @LogAnnotation(module = "addEquipmentModel", operator = "添加设备型号")
    @PostMapping("/adjuration")
    public ResponseResult addEquipmentModel(@RequestBody EquipmentModelDTO equipmentModelDTO) {
        String tips = equipmentModelService.addEquipmentModel(equipmentModelDTO);
        return "添加设备型号成功".equals(tips) ? ResponseResult.SUCCESS(tips) : ResponseResult.FAILED(tips);
    }

    /**
     * 获取设备型号列表
     *
     * @param page     请求页码
     * @param pageSize 每页数量
     * @return 返回设备型号列表json数据
     */
    @ApiOperation("获取设备型号列表")
    @LogAnnotation(module = "listEquipmentModel", operator = "获取设备型号列表")
    @GetMapping("/list/{page}/{pageSize}")
    public ResponseResult listEquipmentModel(@PathVariable int page, @PathVariable int pageSize) {
        if (page <= 0 || pageSize <= 0) {
            return ResponseResult.FAILED("页码参数错误");
        }
        IPage<EquipmentModelDTO> iPage = equipmentModelService.listEquipmentModel(page, pageSize);
        return iPage.getRecords().size() > 0 ? ResponseResult.SUCCESS(iPage) : ResponseResult.FAILED("无数据");
    }
}
